/*
 * @Descripttion: 
 * @Author: lukasavage
 * @Date: 2021-11-24 21:30:50
 * @LastEditors: lukasavage
 * @LastEditTime: 2021-11-24 22:05:23
 */

/**
 * 
 * @param {object} reducers 一个对象，里面有多个reducers方法
 * @returns 返回值是一个新的合并后的reducers
 */
function combineReducers(reducers) {
    return function combination(state = {}, action) {
        let nextState = {}; 
        for (const i in reducers) {
            nextState[i] = reducers[i](state[i], action);
        }
        return nextState;
    }
}

export default combineReducers;















// combineReducers需要做的事情：
/*
    ↓↓↓传入的参数
    {
        add(init, action) {
            return aaa;
        }
        del(init, action) {
            xxx
            return xxx;
        }
    }

    ↓↓↓需要转换成下面的方式
    {
        add: { xxx: xxx },
        del: { xxx: xxx }
    }





*/